package com.csun.cmny.provider.service;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.core.support.IService;
import com.csun.cmny.provider.model.domain.DmcCsunBodyGroup;
import com.csun.cmny.provider.model.domain.DmcDeviceAlert;
import com.csun.cmny.provider.model.dto.DeviceAlertDto;
import com.csun.cmny.provider.model.dto.alert.BatchHandleDeviceAlertDto;
import com.csun.cmny.provider.model.dto.alert.DeviceAlertPageQuery;
import com.csun.cmny.provider.model.dto.alert.HandleDeviceAlertDto;
import com.csun.cmny.provider.model.dto.life.DeviceAlertLifeByIosSelectDto;
import com.csun.cmny.provider.model.vo.*;
import com.csun.cmny.provider.model.vo.csunsleep.CsunSleepVo;
import com.csun.cmny.provider.model.vo.csunsleep.DmcCsunSleepVo;
import com.csun.cmny.provider.model.vo.device.DmcDeviceAlertLifeRoomVo;
import com.csun.cmny.provider.model.vo.device.DmcDeviceAlertLifeVo;
import com.csun.cmny.provider.model.vo.device.DmcDeviceAlertVo;
import com.csun.cmny.provider.model.vo.rfid.DmcRfidLabelVo;
import com.github.pagehelper.PageInfo;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-02-25 13:26
 * @Description: the interface dmc device alert service
 */
public interface DmcDeviceAlertService extends IService<DmcDeviceAlert> {

    /**
     * query device alert list with page
     *
     * @param deviceAlertPageQuery  device alert page query
     *
     * @return  page info
     */
    PageInfo queryDeviceAlertListWithPage(DeviceAlertPageQuery deviceAlertPageQuery);

    /**
     * delete device alert by id
     *
     * @param id    id
     *
     * @return  the int.
     */
    Integer deleteDeviceAlertById(Long id);

    /**
     * batch delete by id list
     *
     * @param deleteIdList  delete id list
     *
     * @return  the int.
     */
    Integer batchDeleteByIdList(List<Long> deleteIdList);

    /**
     * query device alert list by id list
     *
     * @param idList    id list
     *
     * @return  the list.
     */
    List<DmcDeviceAlert> queryDeviceAlertListByIds(List<Long> idList);

    /**
     * read device alert by id
     *
     * @param id            id
     * @param loginAuthDto  login auth dto
     *
     * @return  the int
     */
    Integer readDeviceAlertById(Long id, LoginAuthDto loginAuthDto);

    /**
     * batch read by id list
     *
     * @param readIdList    read id list
     * @param loginAuthDto  login auth dto
     *
     * @return  the int
     */
    Integer batchReadByIdList(List<Long> readIdList, LoginAuthDto loginAuthDto);

    /**
     * handle device alert
     *
     * @param handleDeviceAlertDto  handle device alert dto
     * @param loginAuthDto          login auth dto
     *
     * @return  the int
     */
    Integer handleDeviceAlert(HandleDeviceAlertDto handleDeviceAlertDto, LoginAuthDto loginAuthDto);

    /**
     * csun sleep action alert msg
     *
     * @param deviceNo  device no
     */
    Integer csunSleepAlertMsg(String deviceNo, DmcDeviceAlert dmcDeviceAlert,
                                    OldmanBedRoomBuildingVo obrvo, String sleepFunc);

    /**
     * csun camrea alert msg
     *
     * @param deviceId          the device id
     * @param dmcDeviceAlert    the device alert
     * @param obrvo             the oldman bed room building vo
     * @param msgType           the msg type
     *
     * @return the int.
     */
    Integer csunCameraAlertMsg(Long deviceId, DmcDeviceAlert dmcDeviceAlert,
                               OldmanBedRoomBuildingVo obrvo, String msgType);

    /**
     * device body group alert
     *
     * @param dmcCsunBodyGroup
     * @param dmcDeviceAlert
     * @param obrvo
     *
     * @return  the int.
     */
    Integer deviceBodyGroupAlert(DmcCsunBodyGroup dmcCsunBodyGroup, DmcDeviceAlert dmcDeviceAlert,
                                 OldmanBedRoomBuildingVo obrvo);

    /**
     * csun button alert msg
     *
     * @param deviceNo  device no
     */
    Integer csunButtonAlertMsg(String deviceNo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * csun door alert msg
     *
     * @param deviceNo  the device no
     * @param dmcDeviceAlert    the dmc device alert
     * @param obrvo the oldman bed room building vo
     *
     * @return  thje int.
     */
    Integer csunDoorAlertMsg(String deviceNo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * csun gateway alert msg
     *
     * @param deviceNo  device no
     */
    Integer csunGatewayAlertMsg(String deviceNo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo,String msgType);


    /**
     * csun body sensor alert msg
     *
     * @param deviceNo  device no
     * @param level
     */
    Integer csunBodySensorAlertMsg(String deviceNo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo, Integer level);

    /**
     * 孝心手环报警
     *
     * @param dmcDeviceAlert    the dmc device alert
     * @param obrvo the oldman bed room building vo
     *
     * @return  the int.
     */
    Integer watchAlertMsg(DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * 温度异常报警
     *
     * @param deviceNo          温度传感器编号
     * @param dmcDeviceAlert    报警信息
     * @param obrvo             楼栋楼层信息
     *
     * @return  the int.
     */
    Integer csunHumidistatAlertMsg(String deviceNo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo, String msgType) ;

    /**
     * query device alert by building id and floor no
     *
     * @param deviceReqVoList   device req vo list
     *
     * @return
     */
    List<DmcDeviceAlertVo> queryDeviceAlertByBuildingIdAndFloorNo(List<DeviceReqVo> deviceReqVoList);

    /**
     * update device alert play times by id
     *
     * @param id    device alert id
     *
     * @return  the int.
     */
    Integer updateDeviceAlertPlayTimesById(Long id);

    void sendLifeMsg(DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo oldmanBedRoomBuildingVo, String sound);

    /**
     * send device alert msg
     *
     * @param dmcDeviceAlert            dmc device alert
     * @param oldmanBedRoomBuildingVo   oldman bed room building vo
     */
    void sendDeviceAlertMsg(DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo oldmanBedRoomBuildingVo);

    /**
     * delete device alert msg
     *
     * @param dmcDeviceAlert
     */
    void deleteDeviceAlertMsg(DmcDeviceAlert dmcDeviceAlert);

    /**
     * delete device alert list msg
     *
     * @param dmcDeviceAlertList    dmc device alert list
     */
    void deleteDeviceAlertListMsg(List<DmcDeviceAlert> dmcDeviceAlertList);

    /**
     * delete by device id
     *
     * @param deviceId  device id
     */
    void deleteByDeviceId(Long deviceId);

    /**
     * query device alert by device list
     *
     * @param deviceReqVoList   device req vo list
     *
     * @return  the list
     */
    List<DeviceAlertReqVo> queryDeviceAlertByDeviceList(List<DeviceReqVo> deviceReqVoList);

    /**
     * send sleep data by device id
     *
     * @param deviceId  device id
     */
    void sendSleepDataByDeviceId(Long deviceId);

    /**
     * 批量处理报警信息
     *
     * @param batchHandleDeviceAlertDto the batch handle device alert dto
     * @param loginAuthDto              the login auth dto
     *
     * @return  the int.
     */
    Integer batchHandleByIdList(BatchHandleDeviceAlertDto batchHandleDeviceAlertDto, LoginAuthDto loginAuthDto);

    /*
    * 根据老人id集合和日期查询报警信息
    * */
    List<DeviceAlertReqVo> queryDeviceAlertByOldIdAndDate(DeviceAlertReqVo queryMap);

    /**
     * save rfid reader alert msg
     *
     * @param location          the rfid reader location
     * @param dmcRfidLabelVo    the dmc rfid label vo
     * @param dmcDeviceAlert    the device alert
     * @param obrvo             the oldman bed room building vo
     *
     * @return  the int
     */
    Integer rfidReaderAlertMsg(String location, DmcRfidLabelVo dmcRfidLabelVo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * save rfid reader group alert msg
     *
     * @param alarmLightVo      the alarm light vo
     * @param dmcRfidLabelVo    the dmc rfid label vo
     * @param dmcDeviceAlert    the device alert
     * @param obrvo             the oldman bed room building vo
     *
     * @return  the int.
     */
    Integer rfidReaderGroupAlertMsg(AlarmLightVo alarmLightVo, DmcRfidLabelVo dmcRfidLabelVo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * 通过设备id和起止时间查询报警次数
     * @param: [deviceAlertPageQuery]
     * @return: java.lang.Integer
     */
    Integer countAlertTimesByTypeAndTime(DeviceAlertPageQuery deviceAlertPageQuery);

    /**
     * 通过设备id和起止时间查询报警次数
     * @param: [dmcDeviceAlert]
     * @return: java.lang.Integer
     */
    Integer syncAlertMsgToShiftLog(DmcDeviceAlert dmcDeviceAlert);

    /**
     * 根据老人id查询对应的报警信息
     * @param: oldmanId 老人id
     * @return: the list
     */
    List<DmcDeviceAlertVo> queryDeviceAlertByOldId(Integer oldmanId);



    /**
     * life分页查询报警信息
     * @param:  groupId 机构id
     * @return: the list
     */
    List<DmcDeviceAlertLifeVo> queryDeviceAlertLife(Long groupId);

    /**
     * 根据设备id查询对应的报警信息
     * @param: deviceIds 设备id groupId 机构id
     * @return: the list
     */
    List<DmcDeviceAlertLifeRoomVo> queryDeviceAlertLifeRoom(List<Long> deviceIds,Long groupId);

    /**
     * 处理报警信息
     * @param: alertId 报警id loginName 处理人
     * @return: java.lang.Integer
     */
    Integer updateAlert(Long alertId, String loginName);

    /**
     * 通过房间id查询报警数据
     * @param: id 房间id
     * @return: the list
     */
    List<DmcDeviceAlertLifeRoomVo> selectAlertDataByRoomId(Long id,Long groupId);

    /**
     *
     * @param deviceIds
     * @param groupId
     * @param startTime
     * @param endTime
     * @return
     */
    List<DmcDeviceAlertLifeRoomVo> queryDeviceAlertLifeRoomAndTime(List<Long> deviceIds, Long groupId, Date startTime, Date endTime);

    List<DmcDeviceAlertLifeVo> selectColor(List<Long> alertIds,Long groupId);

    PageInfo queryDeviceAlertLifeRoomIndex(DeviceAlertPageQuery deviceAlertPageQuery);

    Integer updateAlerts(List<Long> alertIds, String loginName);

    Long saveAlert(DmcDeviceAlert deviceAlertDto);

    /**
     * 检测life房间中 老人是否在房间内
     * ======用于设备上传无人消息时，判断是否报警=======
     * @param: roomId groupId startDeviceType
     * @return
     */
    int checkOldmanInRoomAndAlert(Integer roomId, Long groupId, Integer startDeviceType, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * 检测life房间中 老人是否在房间内
     * =======用于定时任务 到了夜间巡视开始时间时，判断老人是否在屋内，是否报警============
     * @param: roomId groupId startDeviceType
     * @return
     */
    int checkOldmanInRoomAndAlert(Integer roomId, Long groupId, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    /**
     * 设备离线报警
     * @param deviceNo
     * @return
     */
    int deviceOfflineAlert(String deviceNo, DmcDeviceAlert dmcDeviceAlert, OldmanBedRoomBuildingVo obrvo);

    List<DmcDeviceAlertLifeVo> queryDeviceAlertLifeByIos(DeviceAlertLifeByIosSelectDto deviceAlertLifeByIosSelectDto);
    //查询该设备最新报警时间
    List<DmcDeviceAlertVo> queryDeviceAlert(DeviceAlertPageQuery deviceAlertPageQuery);
    /**
     * 守护佳床垫报警按时间分布
     * @return Wrapper
     */
    SleepAlertByHour selectSleepAlertByhour(Long groupId);
    //查询床垫报警
    List<com.csun.cmny.provider.model.vo.DmcDeviceAlert> queryDeviceAlertBySleep(List<DmcCsunSleepVo> dmcCsunSleepVos);
}
